package com.zsg.webview.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.zsg.webview.R;
import com.zsg.webview.WeiBoBaseClass.Status;

import java.util.ArrayList;

/**
 * 多图显示的适配器
 * Created by zzc on 2015/11/12.
 */
public class GridAdapter extends BaseAdapter {
    ArrayList<Status.PicURLS> data;
    Context context;
    LayoutInflater inflater;
    int type;

    public static final int SM_PIC=0;       //在列表中显示类型
    public static final int BM_PIC=1;       //在详细中显示类型

    public GridAdapter(Context context, ArrayList<Status.PicURLS> data,int type) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.type=type;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //要加载的图片
        String url = data.get(position).thumbnail_pic;
        if(type==SM_PIC) {
            convertView = inflater.inflate(R.layout.item_imagearr_item, parent, false);
        }else if (type==BM_PIC){
            convertView = inflater.inflate(R.layout.item_imagearr_item2, parent, false);
        }

        ImageView imageView = (ImageView) convertView.findViewById(R.id.imagearr_item);
        Picasso.with(context).load(url).into(imageView);
        return convertView;
    }
}
